//
//  HYReplyBtn.m
//  HaiYue
//
//  Created by skyline on 2018/5/25.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYReplyBtn.h"
@interface HYReplyBtn()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) HYLabel *titleLBL;
@end
@implementation HYReplyBtn
- (instancetype)init
{
    self = [super init];
    if (self)
    {
    }
    return self;
}

- (UIImageView *)imgView
{
    if (!_imgView)
    {
        _imgView = [[UIImageView alloc] init];
        [self addSubview:_imgView];
        [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.right.equalTo(self.titleLBL.mas_left).with.offset(- 3);
        }];
    }
    return _imgView;
}

- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[HYLabel alloc] initWithText:@"0" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.centerY.equalTo(self);
        }];
    }
    return _titleLBL;
}

- (void)setImageName:(NSString *)imageName
{
    if (_imageName != imageName)
    {
        _imageName = imageName;
        self.imgView.image = [UIImage imageNamed:imageName];
    }
}

- (void)setTitle:(NSString *)title
{
    if (_title != title)
    {
        _title = title;
        self.titleLBL.text = _title;
        self.imgView.bounds = CGRectMake(0, 0, self.titleLBL.bounds.size.height *1.1, self.titleLBL.bounds.size.height * 1.1);
        self.bounds = CGRectMake(0, 0, self.titleLBL.bounds.size.width + self.imgView.bounds.size.width + 3 , self.imgView.bounds.size.height);
        
        [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(self.imgView.bounds.size);
        }];
        
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(self.bounds.size);
        }];
    }
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    self.imgView.image = (selected && self.selectImageName)?[UIImage imageNamed:self.selectImageName]:[UIImage imageNamed:self.imageName];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //    DeLog(@"touchtouch");
    [super touchesEnded:touches withEvent:event];
//    [self sendActionsForControlEvents:UIControlEventTouchUpInside];
}

@end
